#!/usr/bin/env python
# -*- coding: utf-8 -*-

""" By Martin Senande-Rivera
    For Spatial and temporal expansion of global wildland fire activity in response to climate change """

import numpy as np
import pandas as pd
import xarray as xr

### File reading ###
FC_1996_2016 ='../2-Classification/'
FC_2070_2099 ='./'

Years_1996_2016 = xr.open_dataset(FC_1996_2016+'Years_FC.nc')
Years_2070_2099 = xr.open_dataset(FC_2070_2099+'Years_FC.nc')
PFS_1996_2016 = xr.open_dataset(FC_1996_2016+'PFS.nc')
PFS_2070_2099 = xr.open_dataset(FC_2070_2099+'PFS.nc')

### Variable calculation ###

Years_present = Years_1996_2016.Years_FC
PFS_present = PFS_1996_2016.PFS

Years_future = Years_2070_2099.Years_FC
PFS_future = PFS_2070_2099.PFS

## Fire-prone years difference ###

dYears = Years_future-Years_present
dYears = xr.where((Years_future==0.) & (Years_present==0.),np.nan,dYears)
dYears.to_netcdf('dYears.nc')

## Potential Fire Season length difference ###

dPFS = PFS_future-PFS_present
dPFS = xr.where((PFS_future==0.) & (PFS_present==0.),np.nan,dPFS)
dPFS.to_netcdf('dPFS.nc')


